﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using EB.Generics;

/// <summary>
/// Summary description for RequestManagement
/// </summary>

namespace EB.BPARequestManagement
{
    public class RequestCreate
    {
        #region Fields
        EB.Generics.Generics commonClass = new EB.Generics.Generics();
        #endregion

        #region Constructor
        public RequestCreate()
        {
            //
            // TODO: Add constructor logic here
            //
        }
       #endregion

        #region Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="RequestTypeID"></param>
        /// <param name="actorID"></param>
        /// <param name="linkKey"></param>
        static int CreateRequest(int RequestTypeID, int actorID, int linkKey)
        {
            #region Fields
            int count=0;
            bool status;
            EB.Generics.Generics commonClass = new EB.Generics.Generics();
            string query = string.Empty;
            object identity = 0;
            int uniqId = 0;
            #endregion
            if (actorID == 0)
            {
                query = "INSERT INTO RequestList(RequestTypeID, RequesterID, LinkKey)" +
        " VALUES     ('" + RequestTypeID + "',NULL,'" + linkKey + "') Select Scope_Identity()";

            }
            else
            {
                query = "INSERT INTO RequestList(RequestTypeID, RequesterID, LinkKey)" +
        " VALUES     ('" + RequestTypeID + "','" + actorID + "','" + linkKey + "') Select Scope_Identity()";

            }
            identity = commonClass.ExecuteScalar(query);
            if (identity != null)
                uniqId = Convert.ToInt16(identity);

            return uniqId;
            //Read connection string from app config
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="RequestTypeName"></param>
        /// <param name="actorID"></param>
        /// <param name="linkKey"></param>
        public int CreateRequest(string RequestTypeName, int actorID, int linkKey)
        {
            int recordNo = 0;
            int requestTypeId = FindRequestTypeId(RequestTypeName);
            if (requestTypeId != 0)
            {
               recordNo=CreateRequest(requestTypeId, actorID, linkKey);
            }
             return recordNo;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="RequestTypeName"></param>
        /// <returns></returns>
        public int FindRequestTypeId(string RequestTypeName)
        {
            #region Fields
            int requestTypeId = 0;
            EB.Generics.Generics commonClass = new EB.Generics.Generics();
            string query = string.Empty;
            #endregion

            query = "SELECT     RequestTypeID   FROM  RequestTypeList where RequestName='" + RequestTypeName + "'";
            object identity = commonClass.ExecuteScalar(query);
            requestTypeId = Convert.ToInt16(identity);
            return requestTypeId;
        }


        public DataSet GetRequestListStatus()
        {
             #region Fields
            string query = string.Empty;
            EB.Generics.Generics commonClass = new EB.Generics.Generics();
            #endregion
            query = "SELECT     Status, StatusNote FROM         RequestListStatus";
            DataSet requestListStatusDS = commonClass.ExecuteQuery(query);
            return requestListStatusDS;
        }
        #endregion
    }
}